import java.sql.*;

public class JdbcTest01 {
    public static void main(String[] args) {

        Connection cnn = null;
        Statement stmt = null;
        ResultSet rt = null;
        //注册驱动
        try {
            Class.forName("com.mysql.jdbc.Driver");
            //获取连接
            cnn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hjy","root","123456");

            //创建数据库操作对象
            stmt = cnn.createStatement();

            //执行sql语句
            rt = stmt.executeQuery("select * from emp");
            System.out.println();

            //处理查询结果集

            /**
             *
             * sdfaf
             * asdfasdf
             * asdf
             */
            while(rt.next()) {

                String ename = rt.getString("ename");
                String sal = rt.getString("sal");
                System.out.println(ename+","+sal);


            }
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        } finally {
            //释放资源
            try {
                rt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                cnn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }

        }

    }
}
